package migrate

import (
	"errors"
	"strings"

	"gitee.com/githubdog/goci"
	"gitee.com/githubdog/goci/system/db/model"
)

var (
	sqldir string
)

func ImportDefaultTable(name string, oConf OtherConf) (err error) {
	readSqlPath()
	if sqldir == "" {
		err = errors.New("sql path read fail")
	} else {
		if !strings.HasSuffix(name, ".sql") {
			name += ".sql"
		}
		m := model.New()
		item, _ := handleMigrate(m, name, sqldir, "", "", 0, oConf)
		err = item.Err
	}
	return
}

func readSqlPath() {
	if sqldir == "" {
		if _sqldir := goci.GetGoCIPath(2); _sqldir != "" {
			sqldir = _sqldir + "/sql"
		}
	}
}
